package com.ruoyi.file.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.file.service.MinioSysFileServiceImpl;
import com.ruoyi.file.utils.FileUploadUtils;
import com.ruoyi.system.api.domain.SysFile;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.File;

@RestController
@RequestMapping("/evaluation")
@Slf4j
public class MinioController {

    @Resource
    private MinioSysFileServiceImpl minioSysFileService;


    @PostMapping("/upload")
    public  R<SysFile>  upload(MultipartFile file) throws Exception {
        try {
            String imageUrl = minioSysFileService.upload(file);
            String filename = FileUploadUtils.extractFilename(file);
            SysFile sysFile = new SysFile(filename, imageUrl);
            return R.ok(sysFile);
        } catch (Exception e) {
            log.error("图片上传失败：{}", e);

        }
        return R.fail("评论照片上传失败");
    }
}
